package org.project.product.android.pfe.fanta.util;

import org.project.product.android.pfe.fanta.R;
import org.project.product.android.pfe.fanta.domain.Category;
import org.project.product.android.pfe.fanta.domain.Product;
import org.project.product.android.pfe.fanta.domain.User;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.EditText;

public final class Utils {

	public static final String CATEGORY_SELECTED = "category_selected";
	public static final String LOGIN = "user";
	public static final String PASSWORD = "fanta";
	public static final String USER_SELECTED = "user_selected";

	public static final String PRODUCT_SELECTED = "product_selected";

	public static void lancerActiviter(Context context,
	        Class<? extends Activity> activityClass) {
		Intent i = new Intent(context, activityClass);
		context.startActivity(i);

	}

	public static void lancerActivity(Context context,
	        Class<? extends Activity> activityClass, Category question) {
		Intent i = new Intent(context, activityClass);
		Bundle bundle = new Bundle();
		bundle.putSerializable(CATEGORY_SELECTED, question);
		i.putExtras(bundle);
		context.startActivity(i);

	}

	public static void lancerActivity(Context context,
	        Class<? extends Activity> activityClass, User user) {
		Intent i = new Intent(context, activityClass);
		Bundle bundle = new Bundle();
		bundle.putSerializable(USER_SELECTED, user);
		i.putExtras(bundle);
		context.startActivity(i);

	}

	public static void lancerActivity(Context context,
	        Class<? extends Activity> activityClass, Product product) {
		Intent i = new Intent(context, activityClass);
		Bundle bundle = new Bundle();
		bundle.putSerializable(PRODUCT_SELECTED, product);
		i.putExtras(bundle);
		context.startActivity(i);

	}

	public static void lancerActivity(Context context,
	        Class<? extends Activity> activityClass) {
		Intent i = new Intent(context, activityClass);
		context.startActivity(i);

	}

	public static void lancerActivityWithCode(Context context,
	        Class<? extends Activity> activityClass, String contentBarCode) {
		Intent i = new Intent(context, activityClass);
		i.putExtra("code", contentBarCode);
		context.startActivity(i);

	}

	public static void lancerActivity(Context context,
	        Class<? extends Activity> activityClass, String capturedQrValue) {
		Intent i = new Intent(context, activityClass);
		i.putExtra("qrcode", capturedQrValue);
		context.startActivity(i);

	}

	public static boolean checkEditText(Context context, EditText... text) {
		boolean isBreaked = false;
		Animation animation = AnimationUtils.loadAnimation(context,
		        R.anim.editextanim);
		for (EditText text2 : text) {
			String value = text2.getText().toString();
			if (value.trim().length() < 1) {
				text2.startAnimation(animation);
				isBreaked = true;
				break;
			}
		}

		return !isBreaked;
	}

	public static void backHome(Context context,
	        Class<? extends Activity> activityClass) {
		Intent intent = new Intent(context, activityClass);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		context.startActivity(intent);
	}

}
